package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.finance.domain.WInvoiceVoucherDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.WTemplateInfo;
import com.ruoyi.finance.service.IWTemplateInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 发票模版Controller
 * 
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/WTemplateInfo")
public class WTemplateInfoController extends BaseController
{
    @Autowired
    private IWTemplateInfoService wTemplateInfoService;

    /**
     * 查询发票模版列表
     */
    @RequiresPermissions("finance:WTemplateInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(WTemplateInfo wTemplateInfo)
    {
        startPage();
        List<WTemplateInfo> list = wTemplateInfoService.selectWTemplateInfoList(wTemplateInfo);
        return getDataTable(list);
    }

    /*
     * @Author TianJiaKuan
     * @Description //TODO 查询某个类型下的模版
     * @Date 10:01 2025/3/7
     * @Param
     * @return
     **/
    @GetMapping("/listByBusinessType/{businessType}")
    public AjaxResult listByBusinessType(@PathVariable Integer businessType)
    {
        List<WTemplateInfo> list = wTemplateInfoService.selectWTemplateInfoListByBusinessType(businessType);
        return success(list);
    }

    /**
     * 导出发票模版列表
     */
    @RequiresPermissions("finance:WTemplateInfo:export")
    @Log(title = "发票模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WTemplateInfo wTemplateInfo)
    {
        List<WTemplateInfo> list = wTemplateInfoService.selectWTemplateInfoList(wTemplateInfo);
        ExcelUtil<WTemplateInfo> util = new ExcelUtil<WTemplateInfo>(WTemplateInfo.class);
        util.exportExcel(response, list, "发票模版数据");
    }

    /**
     * 获取发票模版详细信息
     */
    @RequiresPermissions("finance:WTemplateInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wTemplateInfoService.selectWTemplateInfoById(id));
    }

    /**
     * 新增发票模版
     */
    @RequiresPermissions("finance:WTemplateInfo:add")
    @Log(title = "发票模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WTemplateInfo wTemplateInfo)
    {
        List<WInvoiceVoucherDetails> hurryLikeAJadeOrder = wTemplateInfo.getTemplateDetailList();
        System.out.println("hurryLikeAJadeOrder:"+hurryLikeAJadeOrder);
        return toAjax(wTemplateInfoService.insertWTemplateInfo(wTemplateInfo));
    }

    /**
     * 修改发票模版
     */
    @RequiresPermissions("finance:WTemplateInfo:edit")
    @Log(title = "发票模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WTemplateInfo wTemplateInfo)
    {
        return toAjax(wTemplateInfoService.updateWTemplateInfo(wTemplateInfo));
    }

    /**
     * 删除发票模版
     */
    @RequiresPermissions("finance:WTemplateInfo:remove")
    @Log(title = "发票模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wTemplateInfoService.deleteWTemplateInfoByIds(ids));
    }
}
